from datetime import datetime

from ext import db


class User(db.Model):
    # db.Column(类型， 约束）映射表中的列
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(15), nullable=False)
    password = db.Column(db.String(64), nullable=False)  # 为了加密所以64
    phone = db.Column(db.String(11), unique=True)
    isdelete = db.Column(db.Boolean, default=False)  # 为了逻辑删除
    grade = db.Column(db.Boolean, default=False)
    rdatetime = db.Column(db.DateTime, default=datetime.now)  # 注册时间
    articles = db.relationship('Article', backref='user')

    def __str__(self):
        return self.username

